package com.example.administrator.js_bank;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.CardView;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class LongPayActivity extends AppCompatActivity {

    RecyclerView mRecyclerView;
    CardView mCardView;
    List<Integer> mDatas;
    HomeAdapter mAdapter;
    int[] img;
    String[] names={"扫一扫","收款","向朋友付款","银行卡","AA收款","红包","优惠","快贷","交易记录","快贷付","龙卡贷吧",};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_long_pay);

        initData();


        mCardView=findViewById(R.id.cv_item);
        mRecyclerView = findViewById(R.id.recycler_view);


        mRecyclerView.setLayoutManager(new GridLayoutManager(this,3));
        mRecyclerView.setAdapter(new NormalRecyclerViewAdapter(this));
        mRecyclerView.setAdapter(mAdapter=new HomeAdapter());


    }




    private void initData() {


        mDatas=new ArrayList<Integer>();
        for (int i=1;i<12;i++){
            mDatas.add(i);

        }
        img=new  int[]{
                R.drawable.iv1,R.drawable.iv2,R.drawable.iv3,R.drawable.iv4,R.drawable.iv5,R.drawable.iv6,
                R.drawable.iv7,R.drawable.iv8,R.drawable.iv9,R.drawable.iv10,R.drawable.iv11

        };


    }

    public void back(View view) {

        Intent intent=new Intent(this,MainActivity.class);
        startActivity(intent);

    }

    public void qb(View view) {
        Intent intent=new Intent(this,Main6Activity.class);
        startActivity(intent);

    }

    public void zhifu(View view) {
        Intent intent=new Intent(this,Main4Activity.class);
        startActivity(intent);
    }

    class HomeAdapter extends RecyclerView.Adapter<HomeAdapter.MyViewHolder> {
        @Override
        public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            MyViewHolder holder=new MyViewHolder(LayoutInflater.from(LongPayActivity.this).inflate(R.layout.item_layout,parent,false));
            return holder;
        }

        @Override
        public void onBindViewHolder(final MyViewHolder holder, final int position) {
             holder.tv.setText(names[position].toString());
             holder.iv.setImageResource(img[position]);
             holder.rootView.setOnClickListener(new View.OnClickListener() {
                 @Override
                 public void onClick(View v) {
                     if (position==(R.drawable.iv2)) {
                         iniv();
                     }
                 }
             });
        }

        @Override
        public int getItemCount() {
            return mDatas.size();
        }

        public class MyViewHolder extends RecyclerView.ViewHolder {
            LinearLayout rootView;
            TextView tv;
            ImageView iv;
            public MyViewHolder(View view) {
                super(view);
                rootView = view.findViewById(R.id.root_view);
                tv =  view.findViewById(R.id.text_view);
               iv=view.findViewById(R.id.iv_num);
            }
        }
    }

    private void iniv() {
        Intent intent = new Intent(this,Main4Activity.class);
        startActivity(intent);
    }

}